package ch.ti.bfh.app.loodel.internal;

import ch.ti.bfh.app.loodel.domain.timeslot.TimeSlot;
import ch.ti.bfh.app.loodel.domain.timeslotvote.TimeSlotVote;
import ch.ti.bfh.app.loodel.service.vote.AllMembersTimeSlotVotesData;
import ch.ti.bfh.app.loodel.service.vote.CurrentMemberTimeSlotVoteData;
import ch.ti.bfh.app.loodel.service.vote.TimeSlotVoteData;

import java.util.ArrayList;
import java.util.List;

public final class TimeSlotVoteAssembler {

    public static CurrentMemberTimeSlotVoteData getCurrentMemberTimeSlotVoteData(TimeSlot timeSlot, boolean hasCurrentMemberVoted) {
        CurrentMemberTimeSlotVoteData currentMemberTimeSlotVoteData = new CurrentMemberTimeSlotVoteData();
        currentMemberTimeSlotVoteData.setTimeSlotData(TimeSlotAssembler.getTimeSlotData(timeSlot));
        currentMemberTimeSlotVoteData.setCurrentMemberVoted(hasCurrentMemberVoted);
        return currentMemberTimeSlotVoteData;
    }

    public static List<TimeSlotVoteData> getTimeSlotVoteDataList(List<TimeSlotVote> timeSlotVoteList) {
        List<TimeSlotVoteData> memberVotes1 = new ArrayList<TimeSlotVoteData>();
        for (TimeSlotVote timeSlotVote : timeSlotVoteList) {
            TimeSlotVoteData timeSlotVoteData = new TimeSlotVoteData();
            timeSlotVoteData.setTimeSlotVoteId(timeSlotVote.getId());
            timeSlotVoteData.setVoteTime(timeSlotVote.getCreationTime());
            timeSlotVoteData.setVoter(MemberAssembler.getMemberData(timeSlotVote.getVoter()));
            timeSlotVoteData.setTimeSlotId(timeSlotVote.getTimeSlot().getId());
            memberVotes1.add(timeSlotVoteData);
        }
        return memberVotes1;
    }

    public static AllMembersTimeSlotVotesData buildAllMembersTimeSlotVoteData(TimeSlot timeSlot, boolean currentUserVoted, List<TimeSlotVote> timeSlotVoteList) {
        AllMembersTimeSlotVotesData allMembersTimeSlotVotesData = new AllMembersTimeSlotVotesData();
        allMembersTimeSlotVotesData.setTimeSlotData(TimeSlotAssembler.getTimeSlotData(timeSlot));
        allMembersTimeSlotVotesData.setCurrentMemberVoted(currentUserVoted);
        allMembersTimeSlotVotesData.setTimeSlotAccepted(timeSlot.getTakingPlace());
        List<TimeSlotVoteData> timeSlotVoteDataList = TimeSlotVoteAssembler.getTimeSlotVoteDataList(timeSlotVoteList);
        allMembersTimeSlotVotesData.setMemberTimeSlotVotes(timeSlotVoteDataList);
        return allMembersTimeSlotVotesData;
    }


}